//    Copyright (C) Clear Office.  All rights reserved.
using System;
using Office.Core.Serialization;

namespace Office.Spreadsheet.PivotTable
{
    internal class PivotTableFormat : IOfficeXmlSerializable
    {
        FormatAction _action;
        PivotArea _pivotArea;
        ExtensionList _extLst;
        private DifferentialStyleRecord _differentialStyleRecord;
        private const string xmlName = "format";

        public DifferentialStyleRecord DifferentialStyleRecord
        {
            get { return _differentialStyleRecord; }
        }

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read(xmlName))
            {
                this._action = c.GetOptionalEnum<FormatAction>("action", FormatAction.Formatting);
                int? dxfId = c.GetOptionalInteger("dxfId");
                this._differentialStyleRecord = DifferentialStyleRecordHelper.GetDifferentialStyleRecord(c, dxfId);
                _pivotArea = c.ReadOptionalElement<PivotArea>("pivotArea");
                this._extLst = c.ReadOptionalElement<ExtensionList>("extLst");
            }
        }
        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write(xmlName))
            {
                c.SetOptionalEnum("action", _action, FormatAction.Formatting);
                DifferentialStyleRecordHelper.SetDifferentialStyleRecord(c, this.DifferentialStyleRecord, "dxfId");

                c.WriteOptionalElement(_pivotArea);
                c.WriteOptionalElement(_extLst);
            }
        }
    }

}